const app = getApp();

export const post = (url, data, cb) => {
  let header = { 'Content-Type': 'application/x-www-form-urlencoded' }
  Request(url, data, 'post', cb, header)
}

export const get = (url, data, cb) => {
  Request(url, data, 'get', cb)
}

function Request(url, data, method, cb, header = {}) {
  if (app.globalData.token) {
    header['Authorization'] = 'JWT ' + app.globalData.token
  }
  wx.request({
    url: app.globalData.rootDocment + url,
    data: data,
    method: method,
    header: header,
    complete: (res) => {
      // if
      return typeof cb == "function" && cb(res)
    }
  })
}